package netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @Description http
 * @Author 李龙平
 * @Date 2020/10/12 14:44
 */
public class HttpServerInit extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //向管道加入处理器

        //得到管道
        ChannelPipeline pipeline = socketChannel.pipeline();
        //加入一个netty提供的httpServerCodec 编解码器
        pipeline.addLast("httpServerCodec", new HttpServerCodec());
        //增加一个自定义Handler
        pipeline.addLast("myHandler", new HttpServerHandler());
    }
}
